home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / p_misc / 7p203upp.exe / V203SRC.LZH / 7PLUS.C < prev    next >
C/C++ Source or Header  |  1992-07-17  |  15KB  |  469 lines

  1. /* Version */
  2. #define _7P_VMAJOR 2
  3. #define _7P_VMINOR 03
  4. #define VERSION "2.03"
  5. #define DATE "920717"
  6.  
  7. /*********************************************************************
  8. *** 7PLUS ASCII- Encoder/Decoder, Axel Bauda, DG1BBQ @DB0CL.DEU.EU  ***
  9. **********************************************************************
  10. ***
  11. *** Compile:
  12. *** --------
  13. ***
  14. *** -------
  15. *** | IBM |  : SMALL memory model
  16. *** -------
  17. ***            Turbo C++ and Turbo C 2.0:
  18. ***            MAKE -FTC_MAKE
  19. ***
  20. ***      also: Turbo C++:
  21. ***            Compile in IDE using 7PLUS.PRJ
  22. ***
  23. ***      or  : Turbo C 2.0:
  24. ***            Rename TC2.PRJ to 7PLUS.PRJ and compile in IDE
  25. ***
  26. *** ---------
  27. *** | ATARI |  Pure C 1.0/Turbo C 2.0 : Use 7PLST.PRJ
  28. *** ---------
  29. *** --------
  30. *** | UNIX |   support by Torsten H. Bischoff, DF6NL @ DB0BOX
  31. *** --------
  32. *** Supported systems are:
  33. ***   Interactive UNIX 386
  34. ***   SCO XENIX 386
  35. ***   VAX BSD 4.3/ Ultrix 4.1
  36. ***
  37. *** Compile: make -fu_make
  38. ***
  39. *** -------
  40. *** |AMIGA|    Manx Aztec C 5.1b/5.2:  make -fa_make
  41. *** -------
  42. ***
  43. *** All systems:
  44. *** Signed or unsigned char per default is: don't care.
  45. *** No floating point lib required.
  46. ***
  47. *** TABSIZE when editing: 2; don't insert real TABs (^I), use spaces instead.
  48. ***
  49. *** When porting or modifying this source, make SURE it can still be compiled
  50. *** on all systems! Do this by using #ifdef directives! Please let me know
  51. *** about the modifications or portations, so I can include them in the origi-
  52. *** nal 7PLUS.
  53. ***
  54. **********************************************************************
  55. ***  7PLUS ASCII-Encoder/Decoder, Axel Bauda, DG1BBQ @DB0CL.DEU.EU  ***
  56. **********************************************************************
  57. ***
  58. *** File converter for transfer of arbitrary binary data
  59. *** via store & forward.
  60. ***
  61. *** 7PLUS is HAMWARE. No commercial use. Pass on only in it's entirety!
  62. *** There is no warranty for the proper functioning. Use at own risk.
  63. ***
  64. *** Tnx to:
  65. *** DL1XAO, DB7YAH, DG3YFU and DL6YAV for testing and tips regarding
  66. *** ATARI ST.
  67. *** DB5ZP for his efforts concerning the AMIGA implementation.
  68. *** DF6NL for adding UNIX-compatibility.
  69. ***
  70.  */
  71.  
  72. #include "7plus.h"
  73.  
  74. /** globals **/
  75. uint    crctab[256];
  76. byte    decode[256];
  77. byte    code  [216];
  78. byte    extended = INDICATE;
  79. size_t  buflen;
  80. char    _drive[MAXDRIVE], _dir[MAXDIR], _file[MAXFILE], _ext[MAXEXT];
  81. char    spaces[] = "                                                   ";
  82. char    *endstr;
  83. char    delimit[] = "\n";
  84. char    cant[] = "\007\n'%s': Can't open. Break.\n";
  85. char    notsame[] = "\007Filesize in %s differs from the original file!\nBreak.\n";
  86. int     noquery = 0;
  87. int     force   = 0;
  88. int     fls     = 0;
  89. int     autokill= 0;
  90. struct  m_index *index;
  91.  
  92. #ifdef __TOS__
  93.   int   nowait  = 0;
  94. #endif
  95.  
  96. char logon_ctrl[] =
  97. #ifdef __MSDOS__
  98. "\n╔════════════════════════════════════════════════╗\n║%s║\n║%s║\n╚══════════\
  99. ══════════════════════════════════════╝\n";
  100. #else
  101.  #ifdef __TOS__
  102. "\033p\033v\n%s\n%s\n\033q\n";
  103.  #else
  104.   #ifdef _AMIGA_
  105. "\n\033[3m%s\n%s\033[0m\n\n";
  106.   #else    /* neither __MSDOS__ or __TOS__ or _AMIGA_ */
  107. "\n[]----------------------------------------------[]\n|%s|\n|%s|\n[]---------\
  108. -------------------------------------[]\n";
  109.   #endif   /* ifdef _AMIGA_   */
  110.  #endif   /* ifdef __TOS__   */
  111. #endif   /* ifdef __MSDOS__ */
  112.  
  113. char *logon[] = { "   7PLUS - file converter for store & forward   ",
  114.                   " version "VERSION" ("DATE"), (C) DG1BBQ@DB0CL.DEU.EU " };
  115.  
  116. char *help[] = {
  117. #ifdef _AMIGA_
  118. "\n\033[1mExamples:\n",
  119. "7plus <FILE.7pl>      Decode <FILE.7pl>. create <FILE.err>, if errors detected\n",
  120. "7plus <FILE.p01>      Recombine & decode.                    \"\n",
  121. "7plus <FILE>          Automatically correct and decode.\n",
  122. "                      If a file named <FILE> exists, encode it.\n",
  123. "7plus <FILE>          Encode (automatically split into 10K chunks).\n",
  124. "             -s 30    30 lines/file (max 512 lines/file).\n",
  125. "             -sp 3    3 parts of roughly equal size (max 255 parts).\n",
  126. "             -sb 3000 Parts of roughly 3000 bytes (max 36000).\n",
  127. "7plus <FILE.err> dh0:/pr/ Create correction file. look for <FILE> in dh0:/pr/.\n",
  128. "7plus <FILE.cor>      Use <FILE.cor> to correct metafile <FILE.7mf>.\n",
  129. "7plus <FILE.7pl> -c   Use 7PLUS-file as a correction file.\n",
  130. "7plus <LOGFILE> -x <TEXT> Extract 7plus-files from <LOGFILE>. Only extract a\n",
  131. "                      file, if its name contains <TEXT>. Omit <TEXT> to\n",
  132. "                      extract files in <LOGFILE>.\n",
  133. "7plus <FILE.err> <FILE2.err> -j  Add contents of error report <FILE2err> to\n",
  134. "                      error report <FILE.err>.\n",
  135. "7plus <FILE.err> -j   Add contents of error reports <FILE.eXX> to error\n",
  136. "                      report <FILE.err> (multiple join).\n",
  137. #ifdef _CHSIZE_OK
  138. "7plus <FILE.7mf>      Create new error report from metafile.\n\n",
  139. #else
  140. "7plus <FILE.7ix>      Create new error report from indexfile.\n\n",
  141. #endif
  142. "Other Options:\n",
  143. "-k           Automatically kill all obsolete files.\n",
  144. "-p           Use Packet line separator CR for encoded files. Should be\n",
  145. "             used, when uploading files to the BBS in binary mode!\n",
  146. "-r 5         When encoding, only create part 5. Be sure to split the same\n",
  147. "             way as for the first upload!\n",
  148. "-t /ex       Append string '/ex' to encoded files (BBS file termination).\n",
  149. "-tb <FILE>   Get head and footlines from <FILE> when encoding. See manual.\n",
  150. "-y           Assume YES on all queries.\n",
  151. "-#           Create 7PLUS.FLS when encoding. See Manual.\n",
  152. "\033[0m\n\n",
  153. #else
  154. "\nExamples:\n",
  155. "7plus file.7pl          Decode file.7pl. create file.err, if errors detected.\n",
  156. "7plus file.p01          Recombine & decode.              \"\n",
  157. "7plus file              Automatically correct and decode.\n",
  158. "                        If a file named 'file' exists, encode it.\n",
  159. "7plus file.txt          Encode (automatically split into 10K chunks).\n",
  160. "               -s 30    30 lines/file (max 512 lines/file).\n",
  161. "               -sp 3    3 parts of roughly equal size (max 255 parts).\n",
  162. "               -sb 3000 Parts of roughly 3000 bytes (max 36000).\n",
  163. "7plus file.err c:\\pr\\   Create correction file. look for file.txt in c:\\pr\\.\n",
  164. "7plus file.cor          Use file.cor to correct metafile file.7mf.\n",
  165. "7plus file.7pl -c       Use 7PLUS-file as a correction file.\n",
  166. "7plus logfile -x text   Extract 7plus-files from logfile. Only extract a file\n",
  167. "                        if its name contains 'text'. Omit 'text' to extract\n",
  168. "                        all files in logfile.\n",
  169. "7plus file.err file2.err -j  Add contents of error report file2.err to\n",
  170. "                        error report file.err.\n",
  171. "7plus file.err -j       Add contents of error reports file.eXX to error\n",
  172. "                        report file.err (multiple join).\n",
  173. #ifdef _CHSIZE_OK
  174. "7plus file.7mf          Create new error report from metafile.\n\n",
  175. #else
  176. "7plus file.7ix          Create new error report from indexfile.\n\n",
  177. #endif
  178. "Other Options:\n",
  179. "-k           Automatically kill all obsolete files.\n",
  180. #ifdef __TOS__
  181. "-n           Don't wait for a keystroke at termination.\n",
  182. #endif
  183. "-p           Use Packet line separator CR for encoded files. Should be\n",
  184. "             used, when uploading files to the BBS in binary mode!\n",
  185. "-r 5         When encoding, only create part 5. Be sure to split the same\n",
  186. "             way as for the first upload!\n",
  187. "-t /ex       Append string '/ex' to encoded files (BBS file termination).\n",
  188. "-tb file     Get head and footlines from 'file' when encoding. See manual.\n",
  189. "-y           Assume YES on all queries.\n",
  190. "-#           Create 7PLUS.FLS when encoding. See manual.\n",
  191. #endif
  192. NULLCP
  193. };
  194.  
  195.  
  196. /* Depending on the system, it may be nessesary to prompt the user for a
  197.    keystroke, before terminating, because user wouldn't be able to read
  198.    the outputs to the screen, when the window closes at termination.
  199.    However, the '-n' option overrides this. */
  200. int main (int argc, char **argv)
  201. {
  202. #ifdef __TOS__
  203.   int ret;
  204.   
  205.   ret = go_at_it (argc, argv);
  206.   if ((!nowait || noquery) && !system(NULLCP))
  207.   {
  208.     printf("\n\033p Hit any key \033q");
  209.     getch();
  210.   }
  211.   return (ret);
  212. #else
  213.   return (go_at_it (argc, argv));
  214. #endif
  215. }
  216.  
  217. /* This is the real main() */
  218. int go_at_it (int argc, char **argv)
  219. {
  220.   char *p, *q, *r, *s, *t;
  221.   int  i, extract, join, part, cor;
  222.   long blocksize;
  223.  
  224.   i = extract = join = part = cor = 0;
  225.   p = q = r = s = t = endstr = NULLCP;
  226.  
  227.  
  228.   /* Default blocksize (abt 10000 bytes) */
  229.   blocksize = 138 * 62;
  230.  
  231.   printf (logon_ctrl, logon[0], logon[1]);
  232.  
  233.   while (++i<argc)
  234.   {
  235.     if (*argv[i] != '-')
  236.     {
  237.       if (!p)
  238.       {
  239.         p = argv[i];  /* Name of file to de/encode */
  240.         continue;
  241.       }
  242.       if (!r)
  243.       {
  244.         r = argv[i];  /* Searchpath for non-coded file. Needed for */
  245.         continue;     /* generating correction file */
  246.       }
  247.     }
  248.  
  249.     if (!stricmp (argv[i], "-S")) /* Split option */
  250.     {
  251.       i++;
  252.       if (i == argc)
  253.       {
  254.         blocksize = 512 * 62;  /* No parameter, set max blocksize */
  255.         i--;
  256.       }
  257.       else
  258.         blocksize = atol (argv[i]) * 62; /* Set blocksize to parameter */
  259.     }
  260.  
  261.     if (!stricmp (argv[i], "-SP")) /* Split in equal parts */
  262.     {
  263.       i++;
  264.       if (i == argc)
  265.       {
  266.         blocksize = 0; /* No parameter, no user defined split */
  267.         i--;
  268.       }
  269.       else
  270.         blocksize = 50000L + atol (argv[i]); /* Number of parts to encode */
  271.     }
  272.  
  273.     if (!stricmp (argv[i], "-SB")) /* Split in parts of n bytes */
  274.     {
  275.       i++;
  276.       if (i == argc)
  277.         i--;
  278.       else
  279.         blocksize = (atol (argv[i]) /71 -2) *62;
  280.     }
  281.  
  282.     if (!stricmp (argv[i], "-R")) /* Only reencode part n */
  283.     {
  284.       i++;
  285.       if (i == argc)
  286.         i--;
  287.       else
  288.         part = atoi (argv[i]);
  289.     }
  290.  
  291.     if (!stricmp (argv[i], "-TB")) /* File to get head and foot lines from */
  292.     {
  293.       i++;
  294.       if (i == argc)
  295.         i--;
  296.       else
  297.         t = argv[i];
  298.     }
  299.  
  300.     if (!stricmp (argv[i], "-T")) /* Define BBSs termination string */
  301.     {
  302.       i++;
  303.       if (i == argc)
  304.         i--;
  305.       else
  306.       {
  307.         endstr = malloc ((int) strlen (argv[i]) +1);
  308.         strcpy (endstr, argv[i]);
  309.       }
  310.     }
  311.  
  312.     if (!stricmp (argv[i], "-#")) /* Create 7PLUS.FLS. Contents e.g.:     */
  313.       fls = 1;                    /* 10 TEST */
  314.                                   /* for TEST.EXE encoded into 10 parts   */
  315.  
  316.     if (!stricmp (argv[i], "-C")) /* Use 7PLUS-file as a correction file  */
  317.       cor = 1;
  318.  
  319.     if (!stricmp (argv[i], "-K")) /* Kill obsolete files */
  320.       autokill = 1;
  321.  
  322.     if (!stricmp (argv[i], "-F")) /* Force usage of correction file */
  323.       force = 1;
  324.  
  325.     if (!stricmp (argv[i], "-J")) /* Join two error reports */
  326.       join = 1;
  327.  
  328.     #ifdef __TOS__
  329.     if (!stricmp (argv[i], "-N")) /* Don't wait for a key at termination  */
  330.       nowait = 1;
  331.     #endif
  332.  
  333.     if (!stricmp (argv[i], "-P")) /* Write encoded files in Packet format */
  334.       sprintf (delimit, "\r");    /* for direct binary upload. */
  335.  
  336.     if (!stricmp (argv[i], "-X")) /* Extract 7plus-files from log-file    */
  337.       extract = 1;
  338.  
  339.     if (!stricmp (argv[i], "-VMAJOR")) /* Return version number +100      */
  340.       return (_7P_VMAJOR +100);
  341.  
  342.     if (!stricmp (argv[i], "-VMINOR")) /* Return subversion number + 100  */
  343.       return (_7P_VMINOR+100);
  344.  
  345.     if (!stricmp (argv[i], "-Y")) /* Always assume YES on queries.*/
  346.       noquery = 1;
  347.  
  348.   }
  349.   if (!p ) /* No File specified, show help */
  350.   {
  351.     int n = 4;
  352.     i = 0;
  353.     while (help[i])
  354.     {
  355.       if (++n == 24 && !noquery)
  356.       {
  357.         printf ("Press any key to continue....\r");
  358.         fflush (stdout);
  359.         while (!getch ());
  360.         fflush (stdin);
  361.         n = 0;
  362.         printf ("                             \r");
  363.       }
  364.       printf (help[i++]);
  365.     }
  366.     return (0);
  367.   }
  368.  
  369.   if ((s = malloc (50000U)) == NULLCP)
  370.   {
  371.      printf ("\007Argh error: Not enough memory present! Can't continue.....\n");
  372.      exit (12);
  373.   }
  374.   free (s);
  375.  
  376.   if ((index = (struct m_index *)malloc (sizeof (struct m_index))) == NULL)
  377.   {
  378.     printf ("\007Argh error: Not enough memory present! Can't continue.....\n");
  379.     exit (12);
  380.   }
  381.  
  382.   buflen = 16384;
  383.  
  384.   init_crctab (); /* Initialize table for CRC-calculation */
  385.   init_decodetab (); /* decoding-table */
  386.   init_codetab   (); /* encoding-table */
  387.  
  388.   if (extract)
  389.     if (p)
  390.       return (extract_files (p, r));
  391.     else
  392.     {
  393.       printf ("\007File to extract from not specified. Break.\n");
  394.       return (6);
  395.     }
  396.   if (join)
  397.     return (join_control (p, r));
  398.  
  399.   /* Does the filename contain an extension? */
  400.   if ((q = strrchr (p, '.')) != NULLCP)
  401.   {
  402.     if (cor)
  403.       return (correct_meta (p, 0));
  404.  
  405.     if (!strnicmp (".cor", q, 4) ||
  406.         (toupper(*(q+1)) == 'C' && isxdigit(*(q+2)) && isxdigit(*(q+3))))
  407.       return (correct_meta (p, 1));
  408.  
  409.     /* Call decode_file() if ext ist 7PL, P01, else encode_file() */
  410.     if (!strnicmp (".7pl", q, 4) || !strnicmp (".p01", q, 4))
  411.       return (control_decode (p));
  412.  
  413.     #ifdef _CHSIZE_OK
  414.      if (!strnicmp (".7mf", q, 4))
  415.        return(make_new_err (p));
  416.     #else
  417.      if (!strnicmp (".7ix", q, 4))
  418.        return(make_new_err (p));
  419.     #endif
  420.  
  421.     if (!strnicmp (".x", q, 3))
  422.       return (extract_files (p, r));
  423.  
  424.     return (encode_file (p, blocksize, r, part, t));
  425.   }
  426.   else
  427.   {
  428.     if (!test_exist (p)) /* no EXT, but file exists on disk, then encode */
  429.       return (encode_file (p, blocksize, r, part, t));
  430.     else
  431.       return (control_decode (p));
  432.   }
  433. }
  434.  
  435. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
  436.  *+ Possible return codes:                                                 +*
  437.  *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
  438.  
  439.   0 No errors detected.
  440.   1 Write error.
  441.   2 File not found.
  442.   3 7PLUS header not found.
  443.   4 File does not contain expected part.
  444.   5 7PLUS header corrrupted.
  445.   6 No filename for extracting defined.
  446.   7 invalid error report / correction / index file.
  447.   8 Max number of parts exceeded.
  448.   9 Bit 8 stripped.
  449.  10 User break in test_file();
  450.  11 Error report generated.
  451.  12 Only one or no error report to join
  452.  13 Error report/cor-file does not relate to the same original file
  453.  14 Couldn't write 7plus.fls
  454.  15 Filesize of original file and the size reported in err/cor-file not equal
  455.  16 Correction not successful.
  456.  17 No CRC found in err/cor-file.
  457.  18 Timestamp in metafile differs from that in the correction file.
  458.  19 Metafile already exists.
  459.  
  460.  1XX If invoked with '-VMAJOR' option, 7PLUS returns version number.
  461.      e.g.: 101  <--- v1.5
  462.          : 108  <--- v8.8
  463.  
  464.      Invoked with '-VMINOR':
  465.      e.g.: 150  <--- v1.5
  466.          : 180  <--- v8.8
  467.  
  468.  *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  469.